package com.rtf.framework.web.mvc;

import com.rtf.framework.web.http.AppErrorController;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorMvcAutoConfiguration;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.boot.web.servlet.error.ErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;

import java.util.List;

@Slf4j
@Configuration
@AutoConfigureBefore(ErrorMvcAutoConfiguration.class)
@Order(Ordered.HIGHEST_PRECEDENCE )
public class AppMvcGlobalConfiguration {

    @Bean
    public AppErrorController appErrorController(ErrorAttributes errorAttributes ,
                                                 ObjectProvider<List<ErrorViewResolver>> errorViewResolversProvider) {
        return new AppErrorController(errorAttributes , errorViewResolversProvider.getIfAvailable());
    }

}
